import {
  InputQuestion,
  UploadQuestion,
  QuestionBase,
  TimeQuestion,
  RelateBtnQuestion,
  SelectQuestion,
  RadioQuestion,
  SwitchQuestion,
  CheckboxQuestion,
  CascaderQuestion
} from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { getMenNum } from '@/utils';
import { regExp } from '@/utils/regExp';
import dayjs, { Dayjs } from 'dayjs';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'name',
        label: '活动名称',
        required: true,
        value: '',
        prompt: '请输入活动名称，长度在20个字符之内',
        placeholder: '请输入活动名称，长度在20个字符之内',
        reg: regExp.len020,
        type: 'text',
        order: 1
      }),

      new SelectQuestion({
        key: 'workType',
        label: '类型',
        options: [
          {
            label: '请选择',
            value: null
          },
          {
            label: '图片',
            value: 1
          },
          {
            label: '视频',
            value: 2
          }
        ],
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'stateType'
        },
        order: 2
      }),

      new RadioQuestion({
        key: 'payType',
        label: '售卖价格',
        value: 1,
        options: [
          {
            label: '收费', //未上架
            value: 0
          },
          {
            label: '积分兑换', //已上架
            value: 1
          }
        ],
        state: {
          changeOptions: {
            default: [getMenNum('isActive', 'hidden', true)],
            1: [getMenNum('isActive', 'hidden', false)]
          }
        },
        type: 'text',
        order: 5
      }),

      new SwitchQuestion({
        key: 'isActive',
        label: '状态',
        value: true,
        type: 'text',
        state: {
          activeText: '启用',
          inactiveText: '禁用'
        },
        order: 2
      }),

      new CheckboxQuestion({
        key: 'assignedRoleNames',
        label: '水果',
        options: [
          {
            label: '苹果',
            value: 1
          },
          {
            label: '香蕉',
            value: 2
          },
          {
            label: '橘子',
            value: 3
          }
        ],
        value: [],
        type: 'selectAll',
        state: {
          // url: 'Role/GetRoles',
          // keyName: 'displayName',
          // keyValue: 'name'
          // protType: 'get'
        },
        order: 2
      }),

      new TimeQuestion({
        key: 'startTime',
        label: '活动开始时间',
        value: ['2022-08-31 11:36:34', '2022-09-30 11:36:34'],
        type: 'text',
        required: true,
        state: {
          keySplit: ['startTime', 'endTime']
          //   type:'alone',
          //   disabledDate:(current:any)=>{
          //     return current && current < dayjs().endOf('day');
          //   },
        },
        order: 2
      }),

      new CascaderQuestion({
        key: 'province',
        label: '地址',
        // disabled: true,
        value: [],
        prompt: '输入地址',
        placeholder: '输入地址',
        options: [],
        type: 'area',
        state: {
          labels: [], //选中后的name
          keySplit: ['provinceCode', 'cityCode', 'areaCode'], //拆分字段
          labelSplit: ['province', 'city', 'area'], //配套labels里面数据
          typeSplit: {
            key: 'province',
            value: 'number'
          }, //
          names: {
            value: 'areacode',
            children: 'countryCode',
            label: 'areaname'
          }
        },
        order: 5
      }),

      new UploadQuestion({
        key: 'backgroundImgUrl',
        label: '背景banner',
        // required: true,
        prompt: '请上传图片',
        value: 'http://h5.huicp.cn/files/famous/host/3a061f83a11a11a0e9725f651b0b2638.jpg',
        state: {
          tip: '建议上传宽为750的图片尺寸',
          multiple: true //开启多个上传
          //   multiple:true,
          //   maxCount:10
        },
        order: 6
      }),

      new RelateBtnQuestion({
        key: 'topicList',
        label: '弹层选择',
        // required: true,
        value: [],
        state: {
          table: this.getLayerTables(),
          form: this.getLayerQuestions(),
          index: 0,
          name: 'topicList',
          keyName: 'name',
          keyId: 'id',
          config: {
            title: '选择专题',
            style: 'table-form',
            type: 'layer',
            queryUrl: 'Topic/GetAll',
            keyId: 'id', //选择的key名
            keyName: 'name', //显示的key名
            data: [
              {
                name: '课程1',
                type: 1,
                categoryIds: 0,
                price: 100,
                marketPrice: 120,
                buyerCount: 1000,
                tag: 1,
                shelvesTime: 1663139464524,
                id: '1231213'
              },
              {
                name: '课程2',
                type: 2,
                categoryIds: 1,
                price: 100,
                marketPrice: 120,
                buyerCount: 1000,
                tag: 1,
                shelvesTime: 1663139464524,
                id: '111'
              },
              {
                name: '课程3',
                type: 3,
                categoryIds: 3,
                price: 100,
                marketPrice: 120,
                buyerCount: 1000,
                tag: 1,
                shelvesTime: 1663139464524,
                id: '222'
              },
              {
                name: '课程4',
                type: 4,
                categoryIds: 1,
                price: 100,
                marketPrice: 120,
                buyerCount: 1000,
                tag: 1,
                shelvesTime: 1663139464524,
                id: '333'
              }
            ]
          }
        },
        order: 6
      })
    ];

    return questions.sort((a, b) => a.order - b.order);
  }

  getLayerTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'name',
        value: '课程名称',
        columns: {
          align: 'right'
        },
        order: 3
      }),

      new TextTable({
        key: 'type',
        value: '课程类型',
        order: 4
      }),

      new TextTable({
        key: 'categoryIds',
        value: '状态',
        type: 'dictionary',
        state: {
          filterName: 'stateType'
        },
        tag: {
          0: 'red',
          1: '#108ee9',
          3: '#87d068'
        },
        order: 4
      }),

      new TextTable({
        key: 'price',
        value: '自定义slot',
        type: 'custom', //本地自定义
        columns: {
          customRender: (data: any) => {
            const result = `自定义${data.value}`;
            return result;
          }
        },
        scopedSlots: { customRender: 'recordName' },
        order: 4
      }),

      new TextTable({
        key: 'marketPrice',
        value: '市场价',
        order: 4
      }),

      new TextTable({
        key: 'buyerCount',
        value: '学员数量',
        order: 4
      }),

      new TextTable({
        key: 'shelvesTime',
        value: '上架时间',
        type: 'time',
        order: 4
      })
    ];

    return tables.sort((a, b) => a.order - b.order);
  }

  getLayerQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'Filter',
        label: '关键字',
        value: '',
        type: 'text',
        placeholder: '请输入关键字',
        order: 1
      }),

      new SelectQuestion({
        key: 'Type',
        label: '类型',
        value: null,
        options: [
          {
            label: '请选择',
            value: null
          },
          {
            label: '图文课程',
            value: 1
          },
          {
            label: '视频课程',
            value: 2
          }
        ],
        type: 'text',
        order: 4
      }),

      new SelectQuestion({
        key: 'IsActive',
        label: '状态',
        value: null,
        options: [
          {
            label: '请选择',
            value: null
          },
          {
            label: '已上架',
            value: true
          },
          {
            label: '已下架',
            value: false
          }
        ],
        type: 'text',
        order: 4
      })
    ];
    return questions.sort((a, b) => a.order - b.order);
  }
}

export default new HomeService();
